﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using OwnZTec.Bl;

namespace OwnZTec.Web.conteudoseguro.Administracao
{
    public partial class PerfilListar : Page
    {
        #region -- Membros e construtores -------------------------------------------------------------------------------------------------
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Inicializar();

        }
        #endregion ------------------------------------------------------------------------------------------------------------------------

        #region -- Metodos ----------------------------------------------------------------------------------------------------------------
        public void Inicializar()
        {
            var bl = new BlPerfil();

            var perfis = bl.ListarTodos();

            gvPerfis.DataSource = perfis;
            gvPerfis.DataBind();
        }
        #endregion ------------------------------------------------------------------------------------------------------------------------

        #region -- Eventos ----------------------------------------------------------------------------------------------------------------
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Editar":
                case "Clicar":
                    Response.Redirect("PerfilEditar.aspx?id=" + e.CommandArgument);
                    break;
                case "Deletar":
                    (new BlPerfil()).Excluir(Convert.ToInt32(e.CommandArgument));
                    Inicializar();
                    break;
            }
        }

        protected void GvRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
                for (var i = 1; i < e.Row.Cells.Count; i++)
                    e.Row.Cells[i].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(gvPerfis, "Clicar$" + DataBinder.Eval(e.Row.DataItem, "Id")));
        }
        #endregion ------------------------------------------------------------------------------------------------------------------------
    }
}